/* EzTipsManager */


var EzTipsManager = {};

EzTipsManager = {
    // todo: 找不到得报错
    _tipsBox: function () { return $('#tips'); },
    _tipsw: function () { return $('#tipsw'); },
    _contentw: function () { return $('#contentw'); },

    _currentTips: {},
    _displayedTips: {},


    _hideTipBox: function (theBox, tipId) {
        var self = this;

        self._displayedTips[tipId] = null;

        theBox.hide();
		
		/// 判断整个tips wrapper是否为空
		var isTipswEmpty = self._tipsw().children().length == 1 && Object.count(self._displayedTips) == 0;
		
		  if (isTipswEmpty) {
            self._hideTipsBox();
        }
    },
    _showTipBox: function (theBox, tipId) {
        var self = this;
        if (Object.count(self._displayedTips) == 0) {
            self._showTipsBox();
        }
        self._displayedTips[tipId] = theBox;
        theBox.show();
    },


    _hideTipsBox: function () {
        var self = this;
        self._tipsw().hide();
        self._contentw().width("100%");
    },
    _showTipsBox: function () {
        var self = this;
        self._tipsw().fadeIn();
        self._contentw().width('70%');
    },

    initialize: function () {
        var self = this;
        self._hideTipsBox();
        self._tipsBox().empty();
    },

	// 添加一个新的TipBox
    addTipBox: function (selector, tipId) {
        var self = this;
        if (self._currentTips[tipId]) {
            return;
            // Error 已经存在
        } else {
            var newTipBox = $('<div class="tip"/>')
                                .append($(selector).clone().show())
                                .appendTo(self._tipsBox());

            self._currentTips[tipId] = newTipBox;
            self._hideTipBox(newTipBox, tipId);
        }
    },
	// 从现有TipBox中移除一个
    removeTipBox: function (tipId) {
        var self = this;
        if (self._currentTips[tipId]) {
            var tipBox = self._currentTips[tipId];

            self._hideTipBox(tipBox, tipId);

            tipBox.remove();
            self._currentTips[tipId] = null;
        }
    },
	// 暂时隐藏tipBox
    hideTipBox: function (tipId) {
        var self = this;
        if (self._currentTips[tipId]) {
            var tipBox = self._currentTips[tipId];

            self._hideTipBox(tipBox, tipId);
        }
    },
    showTipBox: function (tipId) {
        var self = this;
        if (self._currentTips[tipId]) {
            var tipBox = self._currentTips[tipId];

            self._showTipBox(tipBox, tipId);
        }
    }
};

$(function () {
//    EzTipsManager.initialize();
	
	var EzTipsManager = {};
});
